# -*- coding: utf-8 -*-
"""
Created on Fri Jul 27 19:32:07 2018

@author: Zhang Yafei
"""

import time
c = "a"
time.clock()
a = 1
b = 2
c = a + b
#1.time.time()#返回当前时间的时间戳

#2.time.localtime()#格式化时间戳为本地时间
time.localtime(time.time())

date = time.localtime(1532691358.9494402)
date
date.tm_mday
date.tm_mon

#3.time.asctime()函数接收时间元组并返回一个可读形式的24位字符串
t = time.localtime()
time.asctime(t)

#4.time.ctime()函数把一个时间戳（按秒计算）转化为time.asctime的形式，默认参数位time.time,
#相当于asctime(localtime(secs))

t = time.localtime()
print(time.asctime(t))
print(time.ctime())

#5.time.strftime()函数接收时间元祖，并返回可读字符串表示的当地时间，格式由参数format决定
print(time.localtime())
print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()))
print(time.strftime('%a %b %d %H:%M:%S %Y',time.localtime()))

#6.time.sleep()函数推迟调用线程的运行，可通过参数secs指秒数，表示进程挂起的时间
time.sleep(4)

#7.time.clock()
start = time.clock()
time.sleep(2)
end = time.clock()
type(end-start)
time = str(end-start)[:4]

#print('开始时间：{0},结束时间：{1},相隔{2}'.format(str(start),str(end),str(end-start))
print('%s-%s相隔：%s秒'%(str(end),str(start),time))
t1 = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
print(t1)
time.sleep(2)
t2 = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
print(t2)
t2-t1

#print('相隔：%s'%t3)
import datetime
str_time = datetime.datetime.strptime(t1,'%Y-%m-%d %H:%M:%S')
str_time2=datetime.datetime.strptime(t2,'%Y-%m-%d %H:%M:%S')
t3 = str_time2-str_time
print(t3.seconds,'秒')


























